<?php
	!defined('DYHB_PATH')&&exit;
	class FilecommentController extends InitController{
		/*处理提交的评论*/
		public function deal(){
			$sub=G::getGpc('comment_sub','p');
			if(!empty($sub)){
					$oComment=new FilecommentModel();
					if($GLOBALS['___login___']==false){
							$oComment->user_name=G::getGpc('comment_name','p');
							$oComment->comment_email=G::getGpc('comment_email','p');
					}else{
						$arrCondition=array('user_id'=>$GLOBALS['___login___']['user_id']);
						$oUser=UserModel::F($arrCondition)->getOne();
						$oComment->user_name=$oUser->regname;
						$oComment->comment_email=$oUser->regemail;
					}
					$oComment->article_id=G::getGpc('gid','g');
					$oComment->comment_content=G::getGpc('comment_content','p');
					$oComment->comment_createdate=date('Y-m-d H:m:s');
					$oComment->save();
					if(!$oComment->isError()){
						$oArt=ArticleModel::F('article_id=?',G::getGpc('gid','g'))->getOne();
						$oArt->article_comments=$oArt->article_comments+1;
						$oArt->save(0,'update');
						$this->assign('__Second__',2);
						$this->S('评论成功');
					}else{
						$this->E($oComment->getErrorMessage());
					}
			}else{
				$this->E('评论失败');
			}
		}
		/*删除评论及该文章的评论减少*/
		public function deleteCom(){
			if($GLOBALS['___login___']==false){
				$this->E('你需要登陆后才能进行此操作');
			}
			$id=G::getGpc('id','g');
			/*$oDb=Db::RUN();
			$sql="SELECT * FROM `blog_filecomment` inner join `blog_article` ON blog_filecomment.article_id=blog_article.article_id and blog_filecomment.comment_id={$id}";
			G::dump($oDb->getAllRows($sql));*/
			$oArt=ArticleModel::F('article_id=?',$id)->getOne();
			if($oArt->article_author!=$GLOBALS['___login___']['regname']){
				 $this->E('你不能删除他人文章的评论');
			}
			$oCom=FilecommentModel::F('comment_id=?',$id)->getOne();
			$id=$oCom->article_id;
			$oCom->destroy();
			if(!$oCom->isError()){
				$oArt->article_comments=$oArt->article_comments-1;
				$oArt->save();
				$this->S("评论删除成功");
			}else{
				$this->E("评论删除失败");
			}
		}
	}
	
?>